function MyPlane() {
	if(!MyPlane.instance) {
		MyPlane.instance = {
			body : document.createElement("div"),
			show : function(){//显示
				this.init(); //初始化
				this.addListener({
					type : "mouse"
				}); //添加监听(鼠标、键盘)
				this.fire();
			},
			init : function() {
				this.body.className = "my-warplain";
				this.body.style.bottom = 0;
				//把我的飞机加入到游戏当中
				new GameEngine().append(this);
				this.body.style.left = new GameEngine().width()/2 - this.width()/2 + "px";
				
			},
			addListener : function(options){ //监听
				switch(options.type) {
					case "key" : { //键盘
						document.addEventListener("keydown", function(e){
							var e = e || event;
							var code = e.keyCode || e.which;
							var mp = new MyPlane();
							if(code == 37) { //向左
								mp.left( Math.max(0, mp.left()-8) );
							} else if(code == 39) {
								mp.left( Math.min(new GameEngine().width()- mp.width() ,mp.left()+8) );
							}
						});
						break;
					}
					case "mouse" : { //鼠标
						new GameEngine().body.addEventListener("mousemove", function(e){
							var e = e || event;
							var _left = e.clientX - new GameEngine().left() - new MyPlane().width()/2;
							new MyPlane().left( Math.min(new GameEngine().width()- new MyPlane().width(), Math.max(0, _left)) );
						});
						break;
					}
				}
			},
			move : function(){ //移动
				
			},
			fire : function(){ //开火（发射子弹）
				setInterval(function(){
					new Bullet().init().move();
				}, new GameEngine().level * 200);
			},
			explode : function(){ //爆炸
				
			},
			upgrade : function(){ //升级
			},
			width : function(){
				return this.body.offsetWidth;
			},
			left : function(val) {
				if(val || val == 0) {
					this.body.style.left = val + "px";
				}
				return this.body.offsetLeft;
			},
			height : function(){
				return this.body.offsetHeight;
			}
		}
	}
	return MyPlane.instance;
}
